logo

overlay

My own overlay for experimentations, use with caution, no support is provided git clone https://hacktivis.me/git/overlay.git

pass-1.7.3-Add support for wl-clipboard.patch (4112B)


  1. From b0b784b1a57c0b06936e6f5d6560712b4b810cd3 Mon Sep 17 00:00:00 2001
  2. From: Brett Cornwall <brett@i--b.com>
  3. Date: Wed, 27 Feb 2019 00:08:33 -0700
  4. Subject: clip: Add support for wl-clipboard
  5. ---
  6. README | 4 +++-
  7. man/pass.1 | 5 +++++
  8. src/password-store.sh | 26 +++++++++++++++++++++-----
  9. 3 files changed, 29 insertions(+), 6 deletions(-)
  10. diff --git a/README b/README
  11. index 6b59965..1a46242 100644
  12. --- a/README
  13. +++ b/README
  14. @@ -19,8 +19,10 @@ Depends on:
  15. http://www.gnupg.org/
  16. - git
  17. http://www.git-scm.com/
  18. -- xclip
  19. +- xclip (for X11 environments)
  20. http://sourceforge.net/projects/xclip/
  21. +- wl-clipboard (for wlroots Wayland-based environments)
  22. + https://github.com/bugaevc/wl-clipboard
  23. - tree >= 1.7.0
  24. http://mama.indstate.edu/users/ice/tree/
  25. - GNU getopt
  26. diff --git a/man/pass.1 b/man/pass.1
  27. index 01a3fbe..a555dcb 100644
  28. --- a/man/pass.1
  29. +++ b/man/pass.1
  30. @@ -99,6 +99,8 @@ Decrypt and print a password named \fIpass-name\fP. If \fI--clip\fP or \fI-c\fP
  31. is specified, do not print the password but instead copy the first (or otherwise specified)
  32. line to the clipboard using
  33. .BR xclip (1)
  34. +or
  35. +.BR wl-clipboard(1)
  36. and then restore the clipboard after 45 (or \fIPASSWORD_STORE_CLIP_TIME\fP) seconds. If \fI--qrcode\fP
  37. or \fI-q\fP is specified, do not print the password but instead display a QR code using
  38. .BR qrencode (1)
  39. @@ -132,6 +134,8 @@ in generating passwords can be changed with the \fIPASSWORD_STORE_CHARACTER_SET\
  40. If \fI--clip\fP or \fI-c\fP is specified, do not print the password but instead copy
  41. it to the clipboard using
  42. .BR xclip (1)
  43. +or
  44. +.BR wl-clipboard(1)
  45. and then restore the clipboard after 45 (or \fIPASSWORD_STORE_CLIP_TIME\fP) seconds. If \fI--qrcode\fP
  46. or \fI-q\fP is specified, do not print the password but instead display a QR code using
  47. .BR qrencode (1)
  48. @@ -466,6 +470,7 @@ The location of the text editor used by \fBedit\fP.
  49. .BR tr (1),
  50. .BR git (1),
  51. .BR xclip (1),
  52. +.BR wl-clipboard (1),
  53. .BR qrencode (1).
  54. .SH AUTHOR
  55. diff --git a/src/password-store.sh b/src/password-store.sh
  56. index d89d455..284eabf 100755
  57. --- a/src/password-store.sh
  58. +++ b/src/password-store.sh
  59. @@ -152,16 +152,32 @@ check_sneaky_paths() {
  60. #
  61. clip() {
  62. + if [[ -n $WAYLAND_DISPLAY ]]; then
  63. + local copy_cmd=( wl-copy )
  64. + local paste_cmd=( wl-paste -n )
  65. + if [[ $X_SELECTION == primary ]]; then
  66. + copy_cmd+=( --primary )
  67. + paste_cmd+=( --primary )
  68. + fi
  69. + local display_name="$WAYLAND_DISPLAY"
  70. + elif [[ -n $DISPLAY ]]; then
  71. + local copy_cmd=( xclip -selection "$X_SELECTION" )
  72. + local paste_cmd=( xclip -o -selection "$X_SELECTION" )
  73. + local display_name="$DISPLAY"
  74. + else
  75. + die "Error: No X11 or Wayland display detected"
  76. + fi
  77. + local sleep_argv0="password store sleep on display $display_name"
  78. +
  79. # This base64 business is because bash cannot store binary data in a shell
  80. # variable. Specifically, it cannot store nulls nor (non-trivally) store
  81. # trailing new lines.
  82. - local sleep_argv0="password store sleep on display $DISPLAY"
  83. pkill -f "^$sleep_argv0" 2>/dev/null && sleep 0.5
  84. - local before="$(xclip -o -selection "$X_SELECTION" 2>/dev/null | $BASE64)"
  85. - echo -n "$1" | xclip -selection "$X_SELECTION" || die "Error: Could not copy data to the clipboard"
  86. + local before="$("${paste_cmd[@]}" 2>/dev/null | $BASE64)"
  87. + echo -n "$1" | "${copy_cmd[@]}" || die "Error: Could not copy data to the clipboard"
  88. (
  89. ( exec -a "$sleep_argv0" bash <<<"trap 'kill %1' TERM; sleep '$CLIP_TIME' & wait" )
  90. - local now="$(xclip -o -selection "$X_SELECTION" | $BASE64)"
  91. + local now="$("${paste_cmd[@]}" | $BASE64)"
  92. [[ $now != $(echo -n "$1" | $BASE64) ]] && before="$now"
  93. # It might be nice to programatically check to see if klipper exists,
  94. @@ -173,7 +189,7 @@ clip() {
  95. # so we axe it here:
  96. qdbus org.kde.klipper /klipper org.kde.klipper.klipper.clearClipboardHistory &>/dev/null
  97. - echo "$before" | $BASE64 -d | xclip -selection "$X_SELECTION"
  98. + echo "$before" | $BASE64 -d | "${copy_cmd[@]}"
  99. ) >/dev/null 2>&1 & disown
  100. echo "Copied $2 to clipboard. Will clear in $CLIP_TIME seconds."
  101. }
  102. --
  103. cgit v1.2.1-28-gf32c